package com.sftz.modules.minapp.homepage.module;

import java.io.IOException;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;

import com.sftz.framework.rersult.MobileResult;
import com.sftz.modules.minapp.homepage.service.UpdataUserAvatarServcie;
import com.sftz.modules.minapp.user.cache.RedissionUserCache;

/**
 * @author   王宏伟
 * @Date	 2018年12月28日 	 
 */
@IocBean
@Ok("josn")
@At("/wx/homepage/updatad/")
public class UpdataUserAvatarModule {
	@Inject
	private UpdataUserAvatarServcie updataUserAvatarServcie;

	/**
	 * 	上传头像
	 * @throws IOException 
	 */
	@At
	@Ok("json")
	@AdaptBy(type = UploadAdaptor.class, args = { "ioc:imgUpload" })
	public Object uploadImage(final @Param("file") TempFile file, @Param("token") final String token) {
		try {
			//id
			Integer userId = RedissionUserCache.getUserId(token);
			String updataUserAvatar = updataUserAvatarServcie.updataUserAvatar(file, userId);
			return updataUserAvatar;
		} catch (IOException e) {
			e.printStackTrace();
			return MobileResult.error("接口调用失败", null);
		}

	}
}
